<%@ page language="java" pageEncoding="utf-8"%>
<script type="text/javascript">

    var CONTEXT_PATH = '${pageContext.request.contextPath}';

    //事件处理器
    function EventHandler(events){
        var that = this;
        that.events = events;
        function handleEvents(){
            for(var i in that.events){
                $(that.events[i].sel).bind(that.events[i].act,that[that.events[i].func]);
            }
        }
        handleEvents();
        return that;
    }

    //继承方法
    function inherit(subClass, superClass) {
        function F() {}
        F.prototype = superClass.prototype;
        subClass.prototype = new F();
        subClass.prototype.constructor = subClass.constructor;
    }



    // 静态类方法

    function ViewHelper(){}
    ViewHelper.template = {};
    ViewHelper.func = {};

    ViewHelper.template.gridOption = {
        onLoadError : function (response){
            if(response.status == 404){
                $.messager.alert('出错啦！','404！服务器提交链接未找到！','error');
            } else if(response.status == 500){
                $.messager.alert('出错啦！','500！服务器提交出错！','error');
            }else{
                $.messager.alert('出错啦！',response.status+'错误！','error');
            }
        } ,
        onLoadSuccess :function (data){
            if(!data.result){
                if(data.info == null){
                    $.messager.alert('出错啦！', '未知错误', 'error');
                }else{
                    $.messager.alert('出错啦！', data.info, 'error');
                }
            }
        }
    };


    ViewHelper.func.gridColumnFormat = function(types, val){
        var i,type;
        for(i in types){
            type = types[i];
            if(type.code == parseInt(val)){
                return type.name;
            }
        }
    };

    ViewHelper.func.ajaxSuccessMessage = function(ret){
        if(ret.result){
            $.messager.show({
                title:'消息提示',
                msg:ret.info,
                timeout:2000,
                showType:'slide',
                style:{
                    right:'',
                    top:document.body.scrollTop+document.documentElement.scrollTop,
                    bottom:''
                }
            });
        }else{
            $.messager.alert('出错啦！',ret.info,'error');
        }
    };

    ViewHelper.func.ajaxErrorMessage = function(response){
        if(response.status == 404){
            $.messager.alert('出错啦！','404！服务器提交链接未找到！','error');
        } else if(response.status == 500){
            $.messager.alert('出错啦！','500！服务器提交出错！','error');
        }else{
            $.messager.alert('出错啦！',response.status+'错误！','error');
        }
    };;;;;

    ViewHelper.func.ajaxWechatErrorMessage = function(response){
        if(response.status == 404){
            alert('404！服务器提交链接未找到！');
        } else if(response.status == 500){
            alert('服务器异常，请稍后重试！');
        }else if(response.status == 504 || response.status == 'timeout'){
            alert('网络异常，请更换网络');
        }else{
            alert(response.status+'错误！');
        }
    };;;;;


    // 兼容以前版本
    EventHandler.templateGridOption = ViewHelper.template.gridOption;

</script>


